package com.example.demo01.demo;

import com.alibaba.fastjson.JSON;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Field;
import java.util.*;

/**
 * @ClassName DemoMain
 * @Description
 * @Author zhangsw
 * @Date 2021/11/2 23:10
 * @Version 1.0
 */
public class DemoMain {

    public static final String str = "{\n" +
            "  \"dataProcessing\" : {\n" +
            "    \"load\" : {\n" +
            "      \"dataCode\" : \"1455477889749626882\",\n" +
            "      \"dataVersion\" : 1,\n" +
            "      \"labelCol\" : \"name\",\n" +
            "      \"featureCols\" : [ \"name\", \"sepal_length\" ]\n" +
            "    },\n" +
            "    \"split\" : {\n" +
            "      \"testRatio\" : 0.1\n" +
            "    },\n" +
            "    \"upSample\" : null,\n" +
            "    \"downSample\" : null,\n" +
            "    \"changeDataType\" : {\n" +
            "      \"inputCols\" : [ ],\n" +
            "      \"newDtypeArray\" : [ ]\n" +
            "    },\n" +
            "    \"filter\" : null,\n" +
            "    \"imputer\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"name\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"strategy\" : 3\n" +
            "      }\n" +
            "    }, {\n" +
            "      \"index\" : \"2\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"sepal_length\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"strategy\" : 1\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"oneHot\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"name\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"binarizer\" : {\n" +
            "      \"inputCols\" : [ \"sepal_length\" ],\n" +
            "      \"thresholds\" : [ 0.2 ]\n" +
            "    },\n" +
            "    \"quantileDiscretizer\" : null,\n" +
            "    \"bucketizer\" : null,\n" +
            "    \"changeScale\" : {\n" +
            "      \"inputCols\" : [ \"sepal_length\" ],\n" +
            "      \"scalesArray\" : [ 1 ]\n" +
            "    },\n" +
            "    \"normalization\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"sepal_length\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"standardization\" : null,\n" +
            "    \"slideWindow\" : null\n" +
            "  },\n" +
            "  \"algrithms\" : [ {\n" +
            "    \"algrithmName\" : \"LinearSVC\",\n" +
            "    \"algrithmParams\" : {\n" +
            "      \"tol\" : 1.0E-6,\n" +
            "      \"fitIntercept\" : true,\n" +
            "      \"classifierMetric\" : 1,\n" +
            "      \"maxIter\" : 100\n" +
            "    }\n" +
            "  } ]\n" +
            "}\n";

    public static final String str2 = "{\n" +
            "  \"dataProcessing\" : {\n" +
            "    \"load\" : {\n" +
            "      \"dataCode\" : \"iris\",\n" +
            "      \"dataVersion\" : 2,\n" +
            "      \"labelCol\" : \"sepal_length\"\n" +
            "    },\n" +
            "    \"split\" : {\n" +
            "      \"testRatio\" : 0.2\n" +
            "    },\n" +
            "    \"upSample\" : {\n" +
            "      \"sampleLabels\" : [ \"1.0\" ],\n" +
            "      \"targetLabels\" : [ \"2.0\" ]\n" +
            "    },\n" +
            "    \"downSample\" : {\n" +
            "      \"sampleLabels\" : [ \"1.0\" ],\n" +
            "      \"targetLabels\" : [ \"2.0\" ]\n" +
            "    },\n" +
            "    \"imputer\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"sepal_length\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"customMissingValue\" : 1.0,\n" +
            "        \"strategy\" : 1,\n" +
            "        \"customFillingValue\" : 1.0\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"changeDataType\" : {\n" +
            "      \"inputCols\" : [ \"sepal_length\" ],\n" +
            "      \"newDtypeArray\" : [ 1 ]\n" +
            "    },\n" +
            "    \"filter\" : {\n" +
            "      \"condition\" : \"sepal_length > 7 \"\n" +
            "    },\n" +
            "    \"oneHot\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"name\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"binarizer\" : {\n" +
            "      \"inputCols\" : [ \"sepal_length\" ],\n" +
            "      \"thresholds\" : [ 0.1 ]\n" +
            "    },\n" +
            "    \"quantileDiscretizer\" : null,\n" +
            "    \"bucketizer\" : null,\n" +
            "    \"changeScale\" : {\n" +
            "      \"inputCols\" : [ \"sepal_length\" ],\n" +
            "      \"scalesArray\" : [ 0 ]\n" +
            "    },\n" +
            "    \"normalization\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"sepal_length\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"standardization\" : null\n" +
            "  },\n" +
            "  \"algrithms\" : [ {\n" +
            "    \"algrithmParams\" : {\n" +
            "      \"timeSeriesPredictorMetrics\" : 1,\n" +
            "      \"timeSeriesPredictorLoss\" : 1,\n" +
            "      \"optimizer\" : 1,\n" +
            "      \"lrStrategy\" : 1,\n" +
            "      \"lrParams\" : {\n" +
            "        \"lr\" : \"0.2\"\n" +
            "      },\n" +
            "      \"batchSize\" : 2,\n" +
            "      \"epochs\" : 1\n" +
            "    },\n" +
            "    \"algrithmName\" : \"AR\"\n" +
            "  } ]\n" +
            "}";

    public static final String str3 = "{\n" +
            "  \"dataProcessing\" : {\n" +
            "    \"load\" : {\n" +
            "      \"dataCode\" : \"iris\",\n" +
            "      \"dataVersion\" : 2,\n" +
            "      \"labelCol\" : \"label\",\n" +
            "      \"featureCols\" : [ \"sepal_length,sepal_width\" ]\n" +
            "    },\n" +
            "    \"split\" : {\n" +
            "      \"testRatio\" : 0.2\n" +
            "    },\n" +
            "    \"upSample\" : {\n" +
            "      \"sampleLabels\" : [ \"1.0\" ],\n" +
            "      \"targetLabels\" : [ \"2.0\" ]\n" +
            "    },\n" +
            "    \"downSample\" : {\n" +
            "      \"sampleLabels\" : [ \"1.0\" ],\n" +
            "      \"targetLabels\" : [ \"2.0\" ]\n" +
            "    },\n" +
            "    \"changeDataType\" : {\n" +
            "      \"inputCols\" : [ \"petal_length\" ],\n" +
            "      \"newDtypeArray\" : [ 1 ]\n" +
            "    },\n" +
            "    \"filter\" : {\n" +
            "      \"condition\" : \"sepal_width > 6 \"\n" +
            "    },\n" +
            "    \"imputer\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"petal_length\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"customMissingValue\" : 2.0,\n" +
            "        \"strategy\" : 1,\n" +
            "        \"customFillingValue\" : 2.0\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"oneHot\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"name\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"binarizer\" : {\n" +
            "      \"inputCols\" : [ \"sepal_width\" ],\n" +
            "      \"thresholds\" : [ 0.2 ]\n" +
            "    },\n" +
            "    \"quantileDiscretizer\" : null,\n" +
            "    \"bucketizer\" : null,\n" +
            "    \"changeScale\" : {\n" +
            "      \"inputCols\" : [ \"sepal_width\" ],\n" +
            "      \"scalesArray\" : [ 1 ]\n" +
            "    },\n" +
            "    \"normalization\" : null,\n" +
            "    \"standardization\" : null,\n" +
            "    \"slideWindow\" : null\n" +
            "  },\n" +
            "  \"algrithms\" : [ {\n" +
            "    \"algrithmName\" : \"MLP\",\n" +
            "    \"algrithmParams\" : {\n" +
            "      \"optimizer\" : 1,\n" +
            "      \"classifierLoss\" : 1,\n" +
            "      \"labelNum\" : 2,\n" +
            "      \"lrStrategy\" : 1,\n" +
            "      \"activations\" : [ 1 ],\n" +
            "      \"layers\" : 2,\n" +
            "      \"lrParams\" : {\n" +
            "        \"lr\" : 1.2\n" +
            "      },\n" +
            "      \"units\" : [ 2, 10 ],\n" +
            "      \"batchSize\" : 2,\n" +
            "      \"epochs\" : 2,\n" +
            "      \"classifierMetrics\" : [ 1 ]\n" +
            "    }\n" +
            "  } ]\n" +
            "}";

    public static final String str4 = "{\n" +
            "  \"dataProcessing\" : {\n" +
            "    \"load\" : {\n" +
            "      \"dataCode\" : \"iris\",\n" +
            "      \"dataVersion\" : 2,\n" +
            "      \"labelCol\" : \"label\"\n" +
            "    },\n" +
            "    \"split\" : {\n" +
            "      \"testRatio\" : 0.5\n" +
            "    },\n" +
            "    \"upSample\" : {\n" +
            "      \"sampleLabels\" : [ \"1.0\", \"1.0\" ],\n" +
            "      \"targetLabels\" : [ \"2.0\", \"2.0\" ]\n" +
            "    },\n" +
            "    \"downSample\" : {\n" +
            "      \"sampleLabels\" : [ \"1.0\", \"1.0\" ],\n" +
            "      \"targetLabels\" : [ \"2.0\", \"2.0\" ]\n" +
            "    },\n" +
            "    \"imputer\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"petal_width\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"customMissingValue\" : 1.0,\n" +
            "        \"strategy\" : 1,\n" +
            "        \"customFillingValue\" : 3.0\n" +
            "      }\n" +
            "    }, {\n" +
            "      \"index\" : \"2\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"petal_length\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"customMissingValue\" : 1.0,\n" +
            "        \"strategy\" : 1,\n" +
            "        \"customFillingValue\" : 3.0\n" +
            "      }\n" +
            "    }, {\n" +
            "      \"index\" : \"3\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"sepal_length\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"customMissingValue\" : 1.0,\n" +
            "        \"strategy\" : 1,\n" +
            "        \"customFillingValue\" : 3.0\n" +
            "      }\n" +
            "    }, {\n" +
            "      \"index\" : \"4\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"sepal_width\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"customMissingValue\" : 1.0,\n" +
            "        \"strategy\" : 1,\n" +
            "        \"customFillingValue\" : 3.0\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"changeDataType\" : {\n" +
            "      \"inputCols\" : [ \"petal_width\", \"petal_length\", \"sepal_length\", \"sepal_width\" ],\n" +
            "      \"newDtypeArray\" : [ 1, 1, 1, 1 ]\n" +
            "    },\n" +
            "    \"filter\" : {\n" +
            "      \"condition\" : \"sepal_length > 7 \"\n" +
            "    },\n" +
            "    \"oneHot\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"name\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"binarizer\" : {\n" +
            "      \"inputCols\" : [ \"sepal_length\" ],\n" +
            "      \"thresholds\" : [ 0.25 ]\n" +
            "    },\n" +
            "    \"quantileDiscretizer\" : null,\n" +
            "    \"bucketizer\" : null,\n" +
            "    \"changeScale\" : {\n" +
            "      \"inputCols\" : [ \"sepal_length\" ],\n" +
            "      \"scalesArray\" : [ 1 ]\n" +
            "    },\n" +
            "    \"normalization\" : null,\n" +
            "    \"standardization\" : null\n" +
            "  },\n" +
            "  \"algrithms\" : [ {\n" +
            "    \"algrithmParams\" : {\n" +
            "      \"tol\" : 10.0,\n" +
            "      \"fitIntercept\" : true,\n" +
            "      \"maxIter\" : 99,\n" +
            "      \"classifierMetric\" : 2\n" +
            "    },\n" +
            "    \"algrithmName\" : \"LinearSVC\"\n" +
            "  } ]\n" +
            "}";

    public static final String str5 = "{\n" +
            "  \"dataProcessing\" : {\n" +
            "    \"load\" : {\n" +
            "      \"dataCode\" : \"iris\",\n" +
            "      \"dataVersion\" : 0,\n" +
            "      \"labelCol\" : \"string\"\n" +
            "    },\n" +
            "    \"split\" : {\n" +
            "      \"testRatio\" : 0.0\n" +
            "    },\n" +
            "    \"imputer\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"string\",\n" +
            "        \"missingType\" : 1,\n" +
            "        \"customMissingValue\" : \"string\",\n" +
            "        \"strategy\" : 1,\n" +
            "        \"customFillingValue\" : \"string\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"changeDataType\" : {\n" +
            "      \"inputCols\" : [ \"string\" ],\n" +
            "      \"newDtypeArray\" : [ 1 ]\n" +
            "    },\n" +
            "    \"filter\" : {\n" +
            "      \"condition\" : \"string \"\n" +
            "    },\n" +
            "    \"oneHot\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"string\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"binarizer\" : {\n" +
            "      \"inputCols\" : [ \"string\" ],\n" +
            "      \"thresholds\" : [ 0.0 ]\n" +
            "    },\n" +
            "    \"bucketizer\" : { },\n" +
            "    \"changeScale\" : {\n" +
            "      \"inputCols\" : [ \"string\" ],\n" +
            "      \"scalesArray\" : [ 0 ]\n" +
            "    },\n" +
            "    \"normalization\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"string\"\n" +
            "      }\n" +
            "    } ],\n" +
            "    \"standardization\" : [ {\n" +
            "      \"index\" : \"1\",\n" +
            "      \"params\" : {\n" +
            "        \"inputCol\" : \"string\"\n" +
            "      }\n" +
            "    } ]\n" +
            "  },\n" +
            "  \"algrithms\" : {\n" +
            "    \"tol\" : 10.0,\n" +
            "    \"fitIntercept\" : true,\n" +
            "    \"maxIter\" : 99,\n" +
            "    \"classifierMetric\" : 2\n" +
            "  }\n" +
            "}";

    public static FlowChartVO flowChart(JobParamConfigBO jobParamConfigBO) throws NoSuchFieldException, IllegalAccessException {

        FlowChartVO.FlowChartVOBuilder builder = FlowChartVO.builder();

        List<FlowChartVO.Node> nodes = new ArrayList<>();

        JobParamConfigBO.DataProcessingBO dataProcessing = jobParamConfigBO.getDataProcessing();

        Map<String, String> mapping = new HashMap<>();

        int index = 0;
        FlowChartRelationEnum[] values = FlowChartRelationEnum.values();
        for (int i = 0; i < values.length - 1; i++) {
            FlowChartRelationEnum value = values[i];
            Field field = dataProcessing.getClass().getDeclaredField(value.getValue());
            field.setAccessible(true);
            Object o = field.get(dataProcessing);
            if (o != null) {
                FlowChartVO.Node.NodeBuilder nodeBuilder = FlowChartVO.Node.builder();
                nodeBuilder.id(value.getId())
                        .label(value.getName())
                        .flag(value.getPosition());
                if (0 == i) {
                    if (++index == 1) {
                        nodeBuilder.type("begin");
                    }
                }
                nodes.add(nodeBuilder.build());
                if (Integer.parseInt(value.getId()) <= 5) {
                    mapping.put("1", value.getId());
                }
                if (Integer.parseInt(value.getId()) >= 6 && Integer.parseInt(value.getId()) <= 7) {
                    mapping.put("21", value.getId());
                }
                if (Integer.parseInt(value.getId()) >= 8 && Integer.parseInt(value.getId()) <= 11) {
                    mapping.put("22", value.getId());
                }
                if (Integer.parseInt(value.getId()) == 12) {
                    mapping.put("3", value.getId());
                }
                if (Integer.parseInt(value.getId()) == 13) {
                    mapping.put("41", value.getId());
                }
                if (Integer.parseInt(value.getId()) == 14) {
                    mapping.put("42", value.getId());
                }
            }
        }

        String algrithmName = jobParamConfigBO.getAlgrithms().get(0).getAlgrithmName();
        FlowChartVO.Node node = FlowChartVO.Node.builder()
                .type("end")
                .label(algrithmName)
                .id(FlowChartRelationEnum.algrithmName.getId())
                .build();
        nodes.add(node);

        List<FlowChartVO.Edge> edges = buildEdges(nodes, mapping);

        for (FlowChartVO.Node n : nodes) {
            n.setFlag(null);
        }
        return builder.nodes(nodes)
                .edges(edges)
                .build();
    }

    public static List<FlowChartVO.Edge> buildEdges(List<FlowChartVO.Node> nodes, Map<String, String> mapping) {
        List<FlowChartVO.Edge> edges = new ArrayList<>();

        int index1 = 0;
        int index2 = 0;
        for (int i = 0; i < nodes.size(); i++) {
            FlowChartVO.Node currNode = nodes.get(i);
            FlowChartVO.Node nextNode = null;
            if (i < nodes.size() - 1) {
                nextNode = nodes.get(i + 1);
            }

            if (Integer.parseInt(currNode.getId()) >= 6 && Integer.parseInt(currNode.getId()) <= 7) {
                if (++index1 == 1) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("1"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                }
            }

            if (Integer.parseInt(currNode.getId()) >= 8 && Integer.parseInt(currNode.getId()) <= 11) {
                if (++index2 == 1) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("1"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                }
            }

            if (Integer.parseInt(currNode.getId()) == 12) {
                if (mapping.get("21") != null) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("21"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                }
                if (mapping.get("22") != null) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("22"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                }
                if (mapping.get("21") == null && mapping.get("22") == null) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("1"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                }
            }

            if (Integer.parseInt(currNode.getId()) == 13) {
                if (mapping.get("3") != null) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("3"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                } else {
                    if (mapping.get("21") != null) {
                        FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                .source(mapping.get("21"))
                                .target(currNode.getId())
                                .build();
                        edges.add(edge);
                    }
                    if (mapping.get("22") != null) {
                        FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                .source(mapping.get("22"))
                                .target(currNode.getId())
                                .build();
                        edges.add(edge);
                    }
                    if (mapping.get("21") == null && mapping.get("22") == null) {
                        FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                .source(mapping.get("1"))
                                .target(currNode.getId())
                                .build();
                        edges.add(edge);
                    }
                }
            }

            if (Integer.parseInt(currNode.getId()) == 14) {
                if (mapping.get("3") != null) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("3"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                } else {
                    if (mapping.get("21") != null) {
                        FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                .source(mapping.get("21"))
                                .target(currNode.getId())
                                .build();
                        edges.add(edge);
                    }
                    if (mapping.get("22") != null) {
                        FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                .source(mapping.get("22"))
                                .target(currNode.getId())
                                .build();
                        edges.add(edge);
                    }
                    if (mapping.get("21") == null && mapping.get("22") == null) {
                        FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                .source(mapping.get("1"))
                                .target(currNode.getId())
                                .build();
                        edges.add(edge);
                    }
                }
            }

            if (Integer.parseInt(currNode.getId()) == 15) {
                if (mapping.get("41") != null) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("41"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                }
                if (mapping.get("42") != null) {
                    FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                            .source(mapping.get("42"))
                            .target(currNode.getId())
                            .build();
                    edges.add(edge);
                }
                if (mapping.get("41") == null && mapping.get("42") == null) {
                    if (mapping.get("3") != null) {
                        FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                .source(mapping.get("3"))
                                .target(currNode.getId())
                                .build();
                        edges.add(edge);
                    } else {
                        if (mapping.get("21") != null) {
                            FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                    .source(mapping.get("21"))
                                    .target(currNode.getId())
                                    .build();
                            edges.add(edge);
                        }
                        if (mapping.get("22") != null) {
                            FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                    .source(mapping.get("22"))
                                    .target(currNode.getId())
                                    .build();
                            edges.add(edge);
                        }
                        if (mapping.get("21") == null && mapping.get("22") == null) {
                            FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                                    .source(mapping.get("1"))
                                    .target(currNode.getId())
                                    .build();
                            edges.add(edge);
                        }
                    }
                }
            }


            if (nextNode != null && currNode.getFlag().equals(nextNode.getFlag())) {
                FlowChartVO.Edge edge = FlowChartVO.Edge.builder()
                        .source(currNode.getId())
                        .target(nextNode.getId())
                        .build();
                edges.add(edge);
            }
        }

        return edges;
    }

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        JobParamConfigBO jobParamConfigBO = JSON.parseObject(str5, JobParamConfigBO.class);
        FlowChartVO flowChartVO = flowChart(jobParamConfigBO);
        System.err.println(JSON.toJSONString(flowChartVO));

    }





    public FlowChartRelationEnum next(JobParamConfigBO.DataProcessingBO dataProcessing, int startIndex, int endIndex) throws IllegalAccessException, NoSuchFieldException {
        FlowChartRelationEnum[] values = FlowChartRelationEnum.values();
        for (int i = startIndex; i < endIndex; i++) {
            FlowChartRelationEnum value = values[i];
            String name = value.getValue();
            Field field = dataProcessing.getClass().getDeclaredField(name);
            field.setAccessible(true);
            Object o = field.get(dataProcessing);
            if (o != null) {
                return value;
            }
        }
        return null;
    }

}
